package com.tedu.cqegmvc.controller;

import com.tedu.cqegmvc.mapper.AddressMapper;
import com.tedu.cqegmvc.pojo.dto.AddressDTO;
import com.tedu.cqegmvc.pojo.dto.AddressUpdateDTO;
import com.tedu.cqegmvc.pojo.entity.Address;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

//@Controller
@RestController
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @RequestMapping("/address/insert")
   // @ResponseBody
    public String add(AddressDTO addressDTO){
        System.out.println("添加地址");
        Address address=new Address();
        BeanUtils.copyProperties(addressDTO,address);
        System.out.println(address);
        addressMapper.insert(address);
        return "添加成功";
    }
    @RequestMapping("/address/select")
   // @ResponseBody
    public String select(){
        System.out.println("查询地址");
        List<Address> addressList=addressMapper.select();
        System.out.println(addressList);

        return "查询成功";
    }
    @RequestMapping("/address/delete")
   // @ResponseBody
    public  String delete(Integer id){
        System.out.println("删除地址,id为："+id);
         addressMapper.deleteById(1);
        return "删除成功";

    }
    @RequestMapping("/address/update")
   // @ResponseBody
    public String update(AddressUpdateDTO addressUpdateDTO){
        System.out.println("修改地址");
        Address address=new Address();
        BeanUtils.copyProperties(addressUpdateDTO,address);
        int num = addressMapper.update(address);
        System.out.println(address);
        return num>0?"修改成功":"修改失败";
    }
}
